/*反馈建议
彭济
9-24*/
import BasicController from './../BasicController'
import ErrorHandlerCode from './../../util/ErrorHandlerCode'
import {TimeLineModel} from '../../model'

class TimelineController extends BasicController{
	insert(req,res){
		if(!super.isEmptyParameter(req.body.timeline_name)){
    		res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'timeline_name 为必填参数'
            })
            return;
    	}
    	if(!super.isEmptyParameter(req.body.timeline_date)){
    		res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'timeline_date 为必填参数'
            })
            return;
    	}
    	if(!super.isEmptyParameter(req.body.timeline_event)){
    		res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'timeline_event 为必填参数'
            })
            return;
    	}
    	if(!super.isEmptyParameter(req.body.is_publish)){
    		res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'is_publish 为必填参数'
            })
            return;
    	}
    	TimeLineModel.insert(req.body).then((data) => {
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
	delTimeLine(req,res,next){
		if(!super.isEmptyParameter(req.body.id)){
    		res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'id 为必填参数'
            })
            return;
    	}
    	TimeLineModel.deleteById(req.body.id).then((data) => {
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
	listpageTimeline(req,res,next){
		if(!super.isEmptyParameter(req.body.page_size)){
    		req.body.page_size = 10;
    	}
    	if(!super.isEmptyParameter(req.body.page_no)){
    		req.body.page_no = 1;
    	}
    	TimeLineModel.findByPage(req.body).then((data) => {
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
	updateTimeline(req,res,next){
		if(!super.isEmptyParameter(req.body.id)){
    		res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'id 为必填参数'
            })
            return;
    	}
		TimeLineModel.update(req.body).then((data) => {
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}

}
module.exports = new TimelineController();